//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.quickserver.net.server.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.quickserver.net.server.ClientHandler;

public class SyncClientIdentifier extends BasicClientIdentifier {
    private static final Logger logger = Logger.getLogger(SyncClientIdentifier.class.getName());

    public SyncClientIdentifier() {
    }

    public ClientHandler findFirstClientById(String id) {
        ClientHandler foundClientHandler = null;
        synchronized(this.getObjectToSynchronize()) {
            Iterator iterator = this.findAllClient();

            while(iterator.hasNext()) {
                foundClientHandler = this.checkClientId((ClientHandler)iterator.next(), id);
                if (foundClientHandler != null) {
                    break;
                }
            }

            return foundClientHandler;
        }
    }

    public Iterator findAllClientById(String pattern) {
        ArrayList list = new ArrayList();
        Pattern p = Pattern.compile(pattern);
        ClientHandler foundClientHandler = null;
        synchronized(this.getObjectToSynchronize()) {
            Iterator iterator = this.findAllClient();

            while(iterator.hasNext()) {
                foundClientHandler = this.checkClientId((ClientHandler)iterator.next(), p);
                if (foundClientHandler != null) {
                    list.add(foundClientHandler);
                }
            }

            return list.iterator();
        }
    }

    public ClientHandler findClientByKey(String key) {
        ClientHandler foundClientHandler = null;
        synchronized(this.getObjectToSynchronize()) {
            Iterator iterator = this.findAllClient();

            while(iterator.hasNext()) {
                foundClientHandler = this.checkClientKey((ClientHandler)iterator.next(), key);
                if (foundClientHandler != null) {
                    break;
                }
            }

            return foundClientHandler;
        }
    }

    public Iterator findAllClientByKey(String pattern) {
        ArrayList list = new ArrayList();
        Pattern p = Pattern.compile(pattern);
        ClientHandler foundClientHandler = null;
        synchronized(this.getObjectToSynchronize()) {
            for(Iterator iterator = this.findAllClient(); iterator.hasNext(); foundClientHandler = null) {
                foundClientHandler = this.checkClientKey((ClientHandler)iterator.next(), pattern);
                if (foundClientHandler != null) {
                    list.add(foundClientHandler);
                }
            }

            return list.iterator();
        }
    }
}
